package com.example.mapreduce.etl;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * ClassName: WebLogMapper
 * Package: com.example.mapreduce.etl
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-07-17
 * Time: 20:56
 */

public class WebLogMapper extends Mapper<LongWritable, Text,Text, NullWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //获取一行
        String s = value.toString();

        //ETL判断是否符合要求
        boolean result = parseLog(s,context);

        if (!result){
            return;
        }
        context.write(value,NullWritable.get());
    }

    private boolean parseLog(String s, Context context) {
        //切割
        String[] s1 = s.split(" ");
        //2.判断日志长度是否大于11
        if (s1.length > 11){
            return true;
        }else {
            return false;
        }
    }
}
